package com.atguigu.lease.web.admin.custom.config;

//import com.atguigu.lease.web.admin.custom.converter.StringToItemTypeConverter;
import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.custom.interceptor.AuthenticationInterceptor;
import com.atguigu.lease.web.admin.custom.interceptor.PermissionInterceptor;
import com.atguigu.lease.web.admin.utils.InterceptorProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

//    @Autowired
//    private StringToItemTypeConverter stringToItemTypeConverter;
//
//    @Override
//    public void addFormatters(FormatterRegistry registry) {
//        registry.addConverter(this.stringToItemTypeConverter);
//    }
    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;


    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    // 配置类获取拦截器属性
    @Autowired
    private InterceptorProperties interceptorProperties;


//    @Autowired
//    private PermissionInterceptor permissionInterceptor;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(this.stringToBaseEnumConverterFactory);
    }

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor)
                .excludePathPatterns(interceptorProperties.getExclude())
                .addPathPatterns(interceptorProperties.getInclude());
//        registry.addInterceptor(permissionInterceptor)
//                .addPathPatterns("/admin/**");
    }

}